package mail

import (
	"bytes"
	"github.com/jordan-wright/email"
	"html/template"
	"net/smtp"
)

func SendMail(toMail, content, htmlTemple, title string) error {
	var (
		err error
		buf = new(bytes.Buffer)
	)
	temp, _ := template.New("test_parse").Parse(htmlTemple)
	if len(content) > 0 {
		temp.Execute(buf, content)
	} else {
		temp.Execute(buf, "")
	}
	e := email.NewEmail()
	e.From = "FX Swift <service@ifcgate.com>"
	e.To = []string{toMail}

	e.Subject = title
	e.HTML = []byte(buf.String())
	err = e.Send(
		"smtppro.zoho.eu:587",
		smtp.PlainAuth("", "service@ifcgate.com", "Yun@20231017", "smtppro.zoho.eu"))
	if err != nil {
		return err
	}
	return nil
}
